class BaseDispatch {
	_callback_list = {};

	isCallBackRegister(key) {
		if (this._callback_list[key + "_sendCallBack"]) {
			return true;
		}
		return false;
	}
	clear() {
		this._callback_list = {};
	}
	registerCallBack(cmd, callback) {
		if (callback) {
			this._callback_list[cmd + "_sendCallBack"] = callback;
		}
	}

	dispacthMessage(cmd, data) {
		var handler = this._callback_list[cmd + "_sendCallBack"];
		if (null == handler) {
			console.log("this._callback_list is no handler for " + cmd);
			return;
		}

		delete this._callback_list[cmd + "_sendCallBack"];
		this._callback_list[cmd + "_sendCallBack"] = null;

		var handlerType = typeof handler;
		if (handlerType == "function") {
			handler(data.errcodedes, data);
		} else if (handlerType == "object") {
			var funcName = "receive" + cmd;
			if (typeof eval("handler." + funcName) == "function") {
				eval("handler." + funcName).bind(handler)(data.errcodedes, data);
			}
		}
	}
}

export let baseDispatch: BaseDispatch = new BaseDispatch();
